﻿CREATE TABLE [dbo].[tUsers]
(
	[userId] INT NOT NULL CONSTRAINT [pk_tUsers_userId] PRIMARY KEY IDENTITY(1,1), 
	[globalId] UNIQUEIDENTIFIER NOT NULL CONSTRAINT [df_tUsers_globalId] DEFAULT NEWID(),
	[userTypeId] INT NOT NULL CONSTRAINT [fk_tUsers_userTypeId] FOREIGN KEY (userTypeId) REFERENCES dbo.[tUserTypes]([userTypeId]),
	[companyId] INT NOT NULL CONSTRAINT [fk_tUsers_companyId] FOREIGN KEY (companyId) REFERENCES dbo.tCompanies([companyId]),
	[firstName] VARCHAR(50) NOT NULL, 
    [lastName] VARCHAR(50) NOT NULL, 
	[email] VARCHAR(80) NOT NULL, 
    [telephone] VARCHAR(50) NULL, 
    [middleName] VARCHAR(50) NULL, 
    [userName] VARCHAR(50) NOT NULL, 
    [passwordHash] VARCHAR(1024) NULL, 
    [passwordSalt] VARCHAR(1024) NULL, 
    [passwordLastChanged] DATETIME2 NULL, 
    [passwordDisabled] BIT NOT NULL CONSTRAINT [df_tUsers_passwordDisabled] DEFAULT 0, 
	[registeredTimeZone] VARCHAR(500) NOT NULL CONSTRAINT [df_tUsers_registeredTimeZone] DEFAULT ('Eastern Standard Time'),
    [isActive] BIT NOT NULL CONSTRAINT [df_tUsers_iaActive] DEFAULT 1, 
    [isDeleted] BIT NOT NULL CONSTRAINT [df_tUsers_isDeleted] DEFAULT 0, 
    [isAdmin] INT NULL, 
    [dateCreated_utc] DATETIMEOFFSET NOT NULL CONSTRAINT [df_tUsers_dateCreated_utc] DEFAULT GETUTCDATE(), 
    [lastUpdated_utc] DATETIMEOFFSET NOT NULL CONSTRAINT [df_tUsers_lastUpdated_utc] DEFAULT GETUTCDATE(), 
    [lastActivityDate_utc] DATETIMEOFFSET NOT NULL CONSTRAINT [df_tUsers_lastActivityDate_utc] DEFAULT GETUTCDATE(), 
    [userRegistered_ip] VARCHAR(50) NULL, 
	[registered_MAC_address] VARCHAR(50),
	[lastActive_MAC_address] VARCHAR(50),
    [lastActivity_ip] VARCHAR(50) NULL
)
